package cn.zhentao.service.Impl;

import cn.zhentao.dao.ZhDao;
import cn.zhentao.pojo.Role;
import cn.zhentao.pojo.User;
import cn.zhentao.service.ZhService;
import cn.zhentao.vo.ZhVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ZhServiceImpl implements ZhService {
    @Autowired
    private ZhDao zhDao;
    @Override
    public List<ZhVo> finda(String uname) {
        List<ZhVo> finda = zhDao.finda(uname);
        return finda;
    }

    @Override
    public List<Role> findr(Integer uid) {
        List<Role> findr = zhDao.findr(uid);
        return findr;
    }

    @Override
    public Role findrc(Integer uid) {
        Role findrc = zhDao.findrc(uid);
        return findrc;
    }

    @Override
    public List<Role> findu() {
        List<Role> findu = zhDao.findu();
        return findu;
    }

    @Override
    public void add(ZhVo zhVo) {
        zhDao.add(zhVo);
        Integer[] rids = zhVo.getRids();
        for (Integer rid : rids) {
            zhDao.add2(zhVo.getUid(),rid);
        }
    }

    @Override
    public int del(Integer[] uid) {
        int a=0;
        for (Integer i : uid) {
            a=zhDao.del(i);
            zhDao.del2(i);
        }
        return a;
    }

    @Override
    public int updateu(ZhVo zhVo) {
        zhDao.updateu(zhVo);
        zhDao.del2(zhVo.getUid());
        Integer[] rids = zhVo.getRids();
        for (Integer rid : rids) {
            zhDao.add2(zhVo.getUid(),rid);
        }
        return 1;
    }

    @Override
    public int updatez(ZhVo zhVo) {
        zhDao.updatez(zhVo);
        return 1;
    }

    @Override
    public ZhVo findn(String username, String password) {
        ZhVo findn = zhDao.findn(username, password);
        return findn;
    }

    @Override
    public List<ZhVo> findmo(String uname) {
        List<ZhVo> findmo = zhDao.findmo(uname);
        return findmo;
    }

    @Override
    public List<ZhVo> finduid(Integer uid) {
        List<ZhVo> finduid = zhDao.finduid(uid);
        return finduid;
    }


}
